package com.ruoyi.project.module.youke.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.module.userinfo.domain.Userinfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.youke.domain.Youke;
import com.ruoyi.project.module.youke.service.IYoukeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 旅客 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-15
 */
@Controller
@RequestMapping("/module/youke")
public class YoukeController extends BaseController
{
    private String prefix = "module/youke";
	
	@Autowired
	private IYoukeService youkeService;
	
	@RequiresPermissions("module:youke:view")
	@GetMapping()
	public String youke()
	{
	    return prefix + "/youke";
	}
	
	/**
	 * 查询旅客列表
	 */
	@RequiresPermissions("module:youke:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Youke youke)
	{
		startPage();
        List<Youke> list = youkeService.selectYoukeList(youke);
		return getDataTable(list);
	}
/**
 * 导出游客
 */
@Log(title = "用户", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:youke:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(Youke youke) throws Exception
{
	try
	{
		List<Youke> list =youkeService.selectYoukeList(youke);
		ExcelUtil<Youke> util = new ExcelUtil<Youke>(Youke.class);
		return util.exportExcel(list, "youke");
	}
	catch (Exception e)
	{
		return error("导出Excel失败，请联系网站管理员！");
	}
}
	
	/**
	 * 新增旅客
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存旅客
	 */
	@RequiresPermissions("module:youke:add")
	@Log(title = "旅客", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Youke youke)
	{		
		return toAjax(youkeService.insertYouke(youke));
	}

	/**
	 * 修改旅客
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Integer userId, ModelMap mmap)
	{
		Youke youke = youkeService.selectYoukeById(userId);
		mmap.put("youke", youke);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存旅客
	 */
	@RequiresPermissions("module:youke:edit")
	@Log(title = "旅客", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Youke youke)
	{		
		return toAjax(youkeService.updateYouke(youke));
	}
	
	/**
	 * 删除旅客
	 */
	@RequiresPermissions("module:youke:remove")
	@Log(title = "旅客", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(youkeService.deleteYoukeByIds(ids));
	}
	
}
